﻿using System;
using PNet.Icap.Platform.PlatformSdk;
using PNet.Icap.PluginSDK.SQLCeAccess.SQLDB;
using PNet.Icap.PluginSDK.SQLCeAccess;

namespace PNet.Icap.Plugins.ShortcutsPlugin.Test 
{
    /// <summary>
    /// 
    /// </summary>
    public partial class dsUser
    {
        public dsUser.tblUserRow GetUser(int id, string strConn)
        {
            cls_tblUser_Select o = new cls_tblUser_Select(strConn);
            o.UserId = id;
            o.Execute(this, new string[] { this.tblUser.TableName });
            if (this.tblUser.Rows.Count > 0)
                return this.tblUser[0];
            else
                return null;
        }

        public void InsertUser(int Id, string email, string strConn)
        {
            cls_tblUser_Insert o = new cls_tblUser_Insert(strConn);
            o.UserId = Id;
            o.Email = email;
            o.DateCreated = DateTime.Now;
            o.ExecuteNonQuery();
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="strConn"></param>
        public void CreateUserTable(string strConn)
        {
            try
            {
                cls_tblUser o = new cls_tblUser(strConn);
                o.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                new PNetException(ex.Message + ex.StackTrace);
            }
        }
    }

    [type_command_info("SELECT * FROM tblUser WHERE 1=1;", CommandExeType.SqlCeCommandText)]
    public class cls_tblUser_Select : SqlCeHelperTable
    {
        [type_param_info(ParamType.Input, "UserId")]
        public int UserId;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strConn"></param>
        public cls_tblUser_Select(string strConn)
            : base(strConn)
        {

        }
    }

    [type_command_info ("INSERT INTO tblUser (UserId, Email, DateCreated) VALUES (?,?,?);", CommandExeType.SqlCeCommandText)]
    public class cls_tblUser_Insert : SqlCeHelperTable
    {
        [type_param_info(ParamType.Input, "UserId")]
        public int UserId;
        [type_param_info(ParamType.Input, "Email")]
        public string Email;
        [type_param_info(ParamType.Input, "DateCreated")]
        public DateTime DateCreated;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="connStr"></param>
        public cls_tblUser_Insert(string connStr)
            : base(connStr)
        {

        }
    }

    [type_command_info("CREATE TABLE tblUser ([UserId] [int] NOT NULL, [Email] [char](40), [DateCreated] [datetime] NOT NULL, CONSTRAINT [PK_tblUser] PRIMARY KEY ([UserId] ASC) WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]", CommandExeType.SqlCeCommandText)]
    public class cls_tblUser : SqlCeHelperTable
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="connStr"></param>
        public cls_tblUser(string connStr)
            : base(connStr)
        {

        }
    }
}
